package com.group.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.group.dao.GeneralBeanDao;
import com.group.model.*;

/**
 * 
 * @author zhaolei
 *
 */
@Service
public class TopicService {
	@Autowired
	GeneralBeanDao beanDao;

	/**
	 * 补充是否点赞和图片信息
	 */
	public void fillTopic(List<Topic> topics, Long userId) {

		// 补充表情,图片信息等
		for (Topic topic : topics) {
			List<Emoji> emojis = beanDao.quickQueryList(Emoji.class, "topicId", topic.getId());

			// 补充用户是否点过表情
			if (userId != null) {
				for (Emoji emoji : emojis) {
					EmojiLog log = new EmojiLog();
					log.setUserId(userId);
					log.setEmojiId(emoji.getId());
					if (beanDao.queryOne(log) != null) {
						emoji.setIsVote(true);
					} else {
						emoji.setIsVote(false);
					}
				}
			}

			topic.setEmojis(emojis);

			// 补充图片信息
			topic.setFile(beanDao.quickQueryOne(FileMap.class, "fileId", topic.getFileId()));
		}

	}

	/**
	 * 补充回复中的表情和图片信息
	 */
	public void fillTopicReply(List<TopicReply> replys, Long userId) {
		// 补充表情
		for (TopicReply reply : replys) {
			List<Emoji> emojis = beanDao.quickQueryList(Emoji.class, "topicReplyId", reply.getId());

			// 补充用户是否点过表情
			if (userId != null) {
				for (Emoji emoji : emojis) {
					EmojiLog log = new EmojiLog();
					log.setUserId(userId);
					log.setEmojiId(emoji.getId());
					if (beanDao.queryOne(log) != null) {
						emoji.setIsVote(true);
					} else {
						emoji.setIsVote(false);
					}
				}
			}

			reply.setEmojis(emojis);
		}
	}

}
